<?php

namespace Modules\Mall\Http\Controllers;
use Illuminate\View\FileViewFinder;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Routing\Controller;
use App;
use Modules\Mall\Entities\Cate;
use Modules\Mall\Entities\MallPic;
use Modules\Mall\Entities\Webset;
use Modules\Mall\Entities\Mall;
use Modules\Mall\Entities\Slider;
use View;
class HomeController extends Controller
{
    /**
     * Display a listing of the resource.
     * @return Response
     */
	public function __construct () {
		//获得public下的templates文件夹路径
		$config=\HDModule::config('admin.config.template');
		$path=[public_path ('templates').'/'.$config];
		//改变模板的目录文件夹,在构造函数中将view加载模板的路径改变，指向我们给定的目录
		View::setFinder (new FileViewFinder(App::make ('files'),$path));
	}
	public function index(){
		$websets=Webset::first();
		$cates=Cate::get();
		$zds=Mall::where('status',1)->orderBy('sort', 'desc')->limit(5)->get();
		$zds_id=Mall::where('status',1)->orderBy('sort', 'desc')->limit(5)->pluck('id');

		$shops=Mall::where('status',1)->orderBy('sort', 'desc')->paginate(20);
		$sliders=Slider::where('isshow',1)->get();
		return view('mindex',compact('shops','cates','websets','sliders','zds'));
	}
	public function lists($id){
		$websets=Webset::first();
		$cates=Cate::all();
		$shops=Mall::where([['cid','=',$id],['status','=',1]])->orderBy('sort', 'desc')->paginate(20);
		$sliders=Slider::where('isshow',1)->get();
		return view('mlist',compact('shops','cates','websets','sliders'));
	}
	public function show($id){
		$shop=Mall::find($id);
		$imgs=MallPic::where('mall_id',$id)->get();
		$sliders=Slider::where('isshow',1)->get();
		//$imgs=explode (';',$shop->pics);
		$websets=Webset::first();
		$cates=Cate::all();
		return view('mcon',compact('shop','websets','cates','imgs','sliders'));
	}
}
